Skip to content

[None][fix] avoid UnboundLocalError in CnnDailymail.compute_score#16261

Open
lonexreb wants to merge 1 commit into
NVIDIA:mainfrom
lonexreb:fix/rouge1-unbound
Open

[None][fix] avoid UnboundLocalError in CnnDailymail.compute_score#16261
lonexreb wants to merge 1 commit into
NVIDIA:mainfrom
lonexreb:fix/rouge1-unbound

Conversation

@lonexreb

@lonexreb lonexreb commented Jul 10, 2026

Copy link
Copy Markdown

Description

CnnDailymail.compute_score (tensorrt_llm/evaluate/cnn_dailymail.py) assigns rouge1 only inside the beam loop:

for beam_idx in range(len(outputs[0].outputs)):
    ...
    if beam_idx == 0:
        rouge1 = metrics["rouge1"] * 100
return rouge1   # UnboundLocalError if outputs[0].outputs is empty

If outputs[0].outputs is empty the loop never runs and return rouge1 raises UnboundLocalError instead of yielding a score.

Change

Initialize rouge1 = 0.0 before the loop.

Test

New CPU-only unit test in tests/unittest/others/test_cnn_dailymail_score.py: compute_score with an empty beam list returns 0.0 (constructed via __new__ to skip the heavy metric-loading __init__).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed CNN/DailyMail evaluation when no beam outputs are available.
    • The evaluator now returns a score of 0.0 instead of failing in this scenario.
  • Tests

    • Added coverage for scoring requests with empty outputs.

When outputs[0].outputs is empty the beam loop never executes, so
'return rouge1' referenced an unbound variable. Initialize rouge1 = 0.0
before the loop.

Signed-off-by: lonexreb <reach2shubhankar@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 26acae8e-f432-45af-bfe5-544a78bfe41c

📥 Commits

Reviewing files that changed from the base of the PR and between b4e7808 and 5a6781d.

📒 Files selected for processing (2)
  • tensorrt_llm/evaluate/cnn_dailymail.py
  • tests/unittest/others/test_cnn_dailymail_score.py

📝 Walkthrough

Walkthrough

CnnDailymail.compute_score now initializes its ROUGE-1 result for empty beam outputs, and a unit test verifies that this case returns 0.0.

Changes

CNN/DailyMail scoring

Layer / File(s) Summary
Empty-beam score handling and regression test
tensorrt_llm/evaluate/cnn_dailymail.py, tests/unittest/others/test_cnn_dailymail_score.py
Initializes rouge1 to 0.0 before beam iteration and tests scoring with an empty outputs list.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the fix and follows the required [None][fix] format.
Description check ✅ Passed The description clearly explains the bug, fix, and test, though it omits the template's explicit Test Coverage and PR Checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant